#!/bin/bash

PATH=/usr/bin:/bin:/usr/sbin:/sbin

if ! /usr/local/sbin/is_primaster; then
	echo -e "Tool \"$0\" is suppposed to be executed on the primary DNS server." >&2
	exit 1
fi

DATE=$(date "+%m/%d/%Y")
TOP20=/var/tmp/top20.$$
cp /dev/null $TOP20

. /etc/named/IT_DNS_SERVERS

sleep 1200

for host in $(echo $DNS_PRIMARY_MASTER $DNS_PSEUDO_MASTERS $DNS_SLAVES); do
	echo -e "\n\n======================== $host ========================\n" >> $TOP20
	ssh -q $host "if [ -f /var/named/tmp/top20 ]; then cat /var/named/tmp/top20; fi" >> $TOP20
#	ssh -q $host "if [ -f /var/named/tmp/top20 ]; then cat /var/named/tmp/top20; rm /var/named/tmp/top20; fi" >> $TOP20
done

cat $TOP20 | mailx -s "[unixmon_audit] Top 20 DNS Queries/Clients on $DATE"  itunix@ebay.com

rm -f $TOP20
